package com.ruoyi.framework.listener;

import com.ruoyi.system.service.IJjzApplyService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.connection.Message;
import org.springframework.data.redis.listener.KeyExpirationEventMessageListener;
import org.springframework.data.redis.listener.RedisMessageListenerContainer;

/**
 * @author Naruto
 * @date 2024/1/20 19:02
 * @description redis Key过期监听
 */
@Slf4j
public class KeyExpiredListener extends KeyExpirationEventMessageListener {

    @Autowired
    private  IJjzApplyService jjzApplyService;

    public KeyExpiredListener(RedisMessageListenerContainer listenerContainer) {
        super(listenerContainer);
    }

    @Override
    public void onMessage(Message message, byte[] pattern) {
        String str = message.toString();

        if(str.contains("APPLY")){
            log.info("过期的key：" + str);
            String[] s = str.split("_");
            String auth = s[1];
            jjzApplyService.checkApplyJjz(auth);
        }

    }
}
